<?php

class Admin_Form_Activity extends Zend_Form
{
    private $id; // l'id de l'utilisateur
    
    public function getId() {
        return $this->id;
    }

    public function setId($id) {
        $this->id = $id;
    }

    
    public function init()
    {
// le nom du formulaire
        $this->setName('formActivity');
        $this->setEnctype(Zend_Form::ENCTYPE_MULTIPART);

//element hidden id pour l'utilisation du formulaire lors de la modification d'un utilisateur
        $id = new Zend_Form_Element_Hidden('id');

//element texte firstname
        $owner_firstname = new Zend_Form_Element_Text('owner_firstname');
        $owner_firstname->setLabel('form_activity_owner_firstname')
                ->setRequired(true)
                ->addValidator('notEmpty')
                ->addFilter('StripTags')
                ->addFilter('StringTrim');
        $owner_name = new Zend_Form_Element_Text('owner_name');
        $owner_name->setLabel('form_activity_owner_name')
                ->setRequired(true)
                ->addValidator('notEmpty')
                ->addFilter('StripTags')
                ->addFilter('StringTrim');
//element texte date
        
        $title = new Zend_Form_Element_Text('title');
        $title->setLabel('form_activity_title')
                ->setRequired(true)
                ->addValidator('notEmpty')
                ->addFilter('StripTags')
                ->addFilter('StringTrim');

//element texte content
        $content = new Zend_Form_Element_Textarea('event_content');
        $content->setLabel('form_activity_content')
                ->setRequired(true)
                ->addValidator('notEmpty');
        
        $image = new Zend_Form_Element_File('image');
        $image->setLabel('form_activity_image')
                ->setDestination("/var/www/appliweb/public/images/")
                ->setMaxFileSize(2097152);
        $image->addValidator('Count', false, 1);
        $image->addValidator('Size', false, 2097152);
        $image->addValidator('Extension', false, 'jpg,jpeg,png,gif');
        
//bouton submit
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setAttrib('id', 'submitbutton')
                ->setLabel('form_user_submit');

// on ajoute tous les éléments du formulaire dans un tableau
        $elements = array($id, $owner_firstname, $owner_name, $title, $content, $image, $submit);

// on ajoute ce tableau d'éléments au formulaire
        $this->addElements($elements);

        $id = $this->getId();
        if (isset($id) && $id != "") {
            $mod = new Application_Model_ActivityModel ( );
            $activityFound = $mod->read($id)->toArray();
            if ($activityFound != null) {
                $this->populate($activityFound);
            } else {
                throw new Zend_Exception("form_user_no_id");
            }
        }
    }


}

